<!-- 选择银行名称 -->
<template>
	<view class="page">
		<view class="search-bar">
			<view class="search-bar-form">
				<view class="search-bar-box">
					<!-- icon0000000000 -->
					<input confirm-type="search" class="search-bar-input" placeholder="输入银行名进行搜索" placeholder-class="phcolor"
					 :value="inputVal" :focus="inputShowed" @input="inputTyping" />
					<view class="icon-clear" v-if="inputVal" @tap="clearInput">
						<!-- #ifdef APP-PLUS || MP -->
						<icon type="clear" :size="15"></icon>
						<!-- #endif -->
						<!-- #ifdef H5 -->
						<!-- #endif -->
					</view>
				</view>
				<label class="search-bar-label" v-if="!inputShowed" @tap="showInput">
					<!-- icon0000000000000000 -->
					<view class="search-bar-text">输入银行名进行搜索</view>
				</label>
			</view>
		</view>
		<scroll-view class="scrollList" scroll-y :style="{height:winHeight+'px'}">
			<view class="uni-list search-result" v-if="inputShowed">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item,index) in searchResult" :key="index"
				 @tap="selectCity" :data-name="item" :hover-stay-time='150'>
					<view class="uni-list-cell-navigate">
						{{item}}
					</view>
				</view>
			</view>
			<view v-if="!inputVal">
				<view class="uni-list city-list">
					<block>
						<view class="uni-list-cell" hover-class="uni-list-cell-hover"  v-for="(list,index) in lists" :key="index"
						 @tap="selectCity" :data-name="list.label" :hover-stay-time='150'>
							<view class="uni-list-cell-navigate">
								{{list.label}}
							</view>
						</view>
					</block>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	const bankData = require('@/utils/bank-data.js')
	export default {
		data() {
			return {
				lists: [],
				titleHeight: 0, // 索引二字距离窗口顶部的高度
				indexBarHeight: 0, // 索引表高度
				indexBarItemHeight: 0, // 索引表子项的高度
				winHeight: 0,
				inputShowed: false, // 输入框是否显示
				inputVal: '', // 搜索框输入的内容
				searchResult: [], // 搜索银行的结果
			}
		},
		onLoad: function(options) {
			
			const that = this;
			that.localCity = options.currentCity || "";
			setTimeout(() => {
				uni.getSystemInfo({
					success: function(res) {
						let winHeight = res.windowHeight
						let barHeight = winHeight - uni.upx2px(204);
						that.winHeight = winHeight;
						that.indexBarHeight = barHeight;
						that.indexBarItemHeight = barHeight / 25;
						that.titleHeight = uni.upx2px(132);
						that.lists = bankData.list
					}
				})
			}, 50)
		},
		methods: {
			showInput() {
				this.inputShowed = true
			},
			clearInput() {
				this.inputVal = "";
				this.inputShowed = false;
				this.searchResult = [];
				uni.hideKeyboard() //强行隐藏键盘
			},
			inputTyping(e) {
				this.inputVal = e.detail.value;
				this.searchCity()
			},
			// 搜索城市
			searchCity() {
				let result = []
					bankData.list.forEach((item, index) => {
						if (item.label.indexOf(this.inputVal.toLocaleUpperCase()) !== -1) {
							result.push(item.label)
						}
					})
				this.searchResult = result
			},
			// 选择城市
			selectCity(e) {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.bank_name = e.currentTarget.dataset.name;
				prevPage.selectBank = true;
				uni.navigateBack();
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
		overflow: hidden;
	}
	.page {
		height: 100%;
		overflow: hidden;
	}
	.scrollList {
		flex: 1;
	}
	.search-bar {
		position: sticky;
		top: 0;
		z-index: 99;
		display: flex;
		align-items: center;
		padding: 27rpx 30rpx 35rpx;
		background-color: #fff;
	}
	.search-bar-form {
		flex: 1;
		position: relative;
		border-radius: 32rpx;
		background: #f2f5f7;
	}
	.search-bar-box {
		display: flex;
		align-items: center;
		position: relative;
		padding-left: 20rpx;
		padding-right: 20rpx;
		height: 64rpx;
		z-index: 1;
	}
	.search-bar-input {
		line-height: normal;
		width: 100%;
		padding-left: 20rpx;
		font-size: 30rpx;
		color: #333;
	}
	.phcolor {
		font-size: 30rpx;
	}
	.icon-clear {
		
		height: 38rpx;
	}
	.icon-clear .uni-icon-class {
		display: block
	}
	.search-bar-label {
		height: 64rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 2;
		border-radius: 32rpx;
		color: #ccc;
		background: #f2f5f7;
	}
	.icon-search {
		position: relative;
		height: 26rpx;
		margin-right: 20rpx;
		font-size: inherit;
	}
	.search-bar-text {
		font-size: 30rpx;
		line-height: 32rpx;
	}
	.cancel-btn {
		padding-left: 30rpx;
	}
	.search-result::before {
		display: none;
	}
	.search-result::after {
		display: none;
	}
	.uni-list-cell {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}
	.uni-list-cell-hover {
		background-color: #eee !important;
	}
	.uni-list-cell-navigate {
		width: 100%;
		position: relative;
		padding: 30rpx 0 30rpx 30rpx;
		font-size: 28rpx;
		color: #333;
	}
	.uni-list-cell-navigate::after {
		content: '';
		position: absolute;
		border-bottom: 1rpx solid #eaeef1;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		bottom: 0;
		right: 0;
		left: 30rpx;
	}
	.uni-icon-class {
		margin-right: 10rpx;
	}
	.city-name {
		display: flex;
		align-items: center;
		margin-top: 17rpx;
		font-size: 30rpx;
		font-weight: bold;
		line-height: 30rpx;
		color: #333;
	}
	.city-names {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-content: space-between;
		width: 630rpx;
		padding: 12rpx 90rpx 26rpx 30rpx;
		background: #fff;
	}
	.city-name-item {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 140rpx;
		height: 56rpx;
		margin-top: 16rpx;
		/* border: solid 1rpx #ccc; */
		border-radius: 28rpx;
		font-size: 28rpx;
		color: #333;
		position: relative;
	}
	.city-name-item::before {
		content: "";
		position: absolute;
		width: 200%;
		height: 200%;
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		-webkit-transform: scale(0.5, 0.5);
		transform: scale(0.5, 0.5);
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		left: 0;
		top: 0;
		border-radius: 56rpx;
		border: 1px solid #ccc;
	}
	.tap-city {
		color: #fff;
		background: #5677fc;
		/* border: solid 1rpx #5677fc; */
	}
	.uni-list {
		background-color: #fff;
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;
		padding-bottom: env(safe-area-inset-bottom);
	}
	.uni-indexed-list-bar {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		z-index: 9999;
		position: absolute;
		top: 132rpx;
		right: 0;
		padding-right: 10rpx;
		width: 44rpx;
	}
	.uni-indexed-list-text {
		font-size: 22rpx;
		white-space: nowrap;
	}
</style>
